<%@ page import="com.actimind.actitime.beans.UserBean,
                 com.actimind.actitime.beans.BillingTypeBean,
                 com.actimind.actitime.Keys,
                 java.sql.Connection,
                 java.util.List,
                 com.actimind.actitime.resources.BillingTypeResource,
                 java.util.Iterator,
                 com.actimind.actitime.beans.AccessRightBean,
                 java.util.Set,
                 com.actimind.actitime.util.CapsuleFactory,
                 com.actimind.actitime.util.Capsule,
                 java.sql.SQLException,
                 com.actimind.actitime.resources.UserResource,
                 org.apache.struts.util.ResponseUtils"%><%@ page errorPage="/error.jsp" %><%

UserBean loggedInUser = (UserBean)session.getAttribute(Keys.LOGGEDIN_USER_KEY);
if (loggedInUser != null)
{
    Capsule c = new Capsule(null);

    try
    {
        UserResource ur = new UserResource();
        BillingTypeResource btr = new BillingTypeResource();

        Connection con = c.getConnection();

        if (loggedInUser.isRoot() || ur.hasUserRight(con, loggedInUser.getId(), "system.manage_billing_types"))
        {
            List typesList  = btr.getAllTypes(con);

%>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> Billing Types</title>

    <link rel="stylesheet" href="../css/at.css" type="text/css">
</head>

<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="administration" />
    <jsp:param name="pageAction" value="btlist" />
</jsp:include>

<form>
<table cellspacing="0" cellpadding="5" align="center" valign="top" border="0" bgcolor="#ffffff" width="770">
<tr>
    <td class="pagetitle">
        Billing Types
    </td>
    <td align="right">
        <input type="button" value="Add New Billing Type" onclick="javascript:document.location.href='<html:rewrite page="/administration/btadd.do"/>'" />
    </td>
</tr>
<tr>
    <td colspan="2" class="pagetitle">
        <at:errors />
        <at:messages id="message" message="true">
            <span class="successmsg"><bean:write name="message"/></span>
        </at:messages>
    </td>
</tr>
<tr>
    <td colspan="2">
        <table border="0" cellspacing="1" cellpadding="5"  align="center" width="770">
        <tr>
            <th class="listtblcolheader" align="left">Billing Type</th>
            <th width="25%" class="listtblcolheader">Status</th>
        </tr>
<%
            Iterator it = typesList.iterator();

            BillingTypeBean type = null;

            while (it.hasNext())
            {
                type = (BillingTypeBean)it.next();

%>
        <tr>
            <td class="listtblcell"><html:link href='<%="btedit.do?typeId=" + type.getId()%>'><%=ResponseUtils.filter(type.getName())%></html:link></td>
<%
                if (btr.isTypeInUse(con, type.getId()))
                {
%>            <td class="listtblcell" nowrap="1" align="center">In Use</td>
<%
                }
                else
                {
%>            <td class="listtblcell" align="center"><span class="textinactive">Unused</span><br />
<%
                    if (btr.isTypeDeletable(con, type.getId()))
                    {
%><html:link href='<%="btdelete.do?typeId=" + type.getId()%>' onclick="return confirm('Are you sure you want to delete this billing type?')">delete this billing type</html:link></td>
<%
                    }
                }
%>
        </tr>
<%
            }
%>
        </table>
    </td>
</tr>
</table>
</form>

</body>
</html>
<%
        }
        else
        {
            response.sendRedirect("../login.do");
        }
    }
    finally
    {
        if (c != null)
            c.cleanup();
    }
}
else
{
    response.sendRedirect("../login.do");
}
%>